/*
package com.example.security.component;

import com.example.security.config.CustomUserDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerSecurityConfiguration;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer;
import org.springframework.security.oauth2.provider.token.TokenStore;

@EnableAuthorizationServer
@Configuration
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {

    @Autowired
    private TokenStore tokenStore;
    @Autowired
    private CustomUserDetailsService userService;
    @Autowired
    private AuthenticationManager authenticationManagerBean;
    @Autowired
    private PasswordEncoder passwordEncoder;

    // 配置令牌(token）的访问端点和令牌服务(tokenservices)
    public void configure(AuthorizationServerEndpointsConfigurer authorizationServerEndpointsConfigurer){
        authorizationServerEndpointsConfigurer.authenticationManager(authenticationManagerBean)  // 使用密码模式的声明
                .tokenStore(tokenStore) // 把token存放进redis中
                .reuseRefreshTokens(false)  //refresh_token是否重复使用
                .userDetailsService(userService)  // 刷新令牌时 对用户的检查
                .allowedTokenEndpointRequestMethods(HttpMethod.GET,HttpMethod.POST); //支持GET、POST请求
    }
    // 令牌的安全性约束
    public void configure(AuthorizationServerSecurityConfigurer authorizationServerSecurityConfigurer){
        authorizationServerSecurityConfigurer.allowFormAuthenticationForClients();  // 允许表单验证
    }
    // 客户端详情信息存放处  也可从数据库中取  相当于存储账号密码的地方
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
        clients
                .inMemory()
                //配置client_id
                .withClient("client")
                //配置client_secret
                .secret(passwordEncoder.encode("123123"))
                //配置访问token的有效期
                .accessTokenValiditySeconds(3600)
                //配置刷新token的有效期
                .refreshTokenValiditySeconds(864000)
                //配置redirect_uri，用于授权成功后跳转
                .redirectUris("http://www.baidu.com")
                //配置申请的权限范围
                .scopes("all")
                */
/**
                 * 配置grant_type，表示授权类型
                 * authorization_code: 授权码模式
                 * implicit: 简化模式
                 * password： 密码模式
                 * client_credentials: 客户端模式
                 * refresh_token: 更新令牌
                 *//*

                .authorizedGrantTypes("authorization_code","implicit","password","client_credentials","refresh_token");
    }
}
*/
